import { Page } from '@/base/Page';
import { deleteMusic, getMusicList} from '@/base/api/MusicApi';
import { Music } from '@/base/model/Music';

class Form {
  id = 0;
  musicName = '';
  englishName = '';
  musicUrl = '';
  imgUrl = '';
  created = '';
  updated = '';
  date = [];
}

export class ListBloc {
  form = new Form();

  paged: Page<Music> = new Page<Music>([], 0, 1, 15, 0, []);

  load(pageIndex: number, pageSize: number) {
    return getMusicList({
      pageIndex,
      pageSize,
      musicName: this.form.musicName,
      englishName: this.form.englishName
    }).then((res) => {
      this.paged = res.data;
    })
  }

  removeItem(dateItem: Music) {
    return deleteMusic(dateItem.id)
  }

  reset() {
    this.form = new Form();
    this.paged.pageIndex = 1;
    this.paged.pageSize = 15;
    this.load(this.paged.pageIndex, this.paged.pageSize);
  }

}
